package com.yz.jdd.module.psd.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.trello.rxlifecycle.ActivityEvent;
import com.yz.jdd.R;
import com.yz.jdd.base.activity.BaseActivity;
import com.yz.jdd.base.event.Events;
import com.yz.jdd.base.event.RxBus;
import com.yz.jdd.base.utils.EditTextUtils;
import com.yz.jdd.module.login.view.LoginActivity;
import com.yz.jdd.module.psd.presenter.ForgetPsdPresenter;
import com.yz.jdd.widget.TimerButton;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.functions.Action1;

/**
 * Created by cc on 2017/5/15.
 */

public class ForgetPsdActivity extends BaseActivity implements ForgetPsdView{
    @BindView(R.id.top_back)
    ImageView topBack;
    @BindView(R.id.top_title)
    TextView topTitle;
    @BindView(R.id.top_right)
    TextView topRight;
    @BindView(R.id.tel_no)
    EditText telNo;
    @BindView(R.id.verify_code)
    EditText verifyCode;
    @BindView(R.id.verify_get)
    TimerButton verifyGet;

    @BindView(R.id.btn_next)
    Button btnNext;
    private ForgetPsdPresenter presenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forgetpsd);
        ButterKnife.bind(this);
        presenter=new ForgetPsdPresenter(this);
        RxBus.with(this).setEvent(Events.EVENT_MODFIFYPSD_SUCCESS).setEndEvent(ActivityEvent.DESTROY).onNext(new Action1<Events<?>>() {
            @Override
            public void call(Events<?> events) {
                finish();
            }
        }).create();
        initView();
    }

    private void initView() {
        topTitle.setText("手机验证");
        topBack.setVisibility(View.VISIBLE);topRight.setVisibility(View.VISIBLE);
        topRight.setText("下一步");
        topRight.setVisibility(View.GONE);
        String tel_no=getIntent().getStringExtra("tel_no")+"";
        telNo.setText(tel_no);
        EditTextUtils.inputTextCheck(btnNext, Arrays.<TextView>asList(telNo,verifyCode));
    }

    @OnClick({R.id.top_back, R.id.top_right, R.id.verify_get, R.id.btn_next})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.top_back:
                finish();
                break;
            case R.id.top_right:
                presenter.verifyCode("forget");
                break;
            case R.id.verify_get:
                presenter.getVerifyCode("2");
                break;
            case R.id.btn_next:
                presenter.verifyCode("forget");
                break;
        }
    }

    @Override
    public void startLoginActivity() {
        startActivity(new Intent(this,LoginActivity.class));
    }

    @Override
    public void colseActivity(String phoneNo) {

        finish();
    }

    @Override
    public String getPhoneNumber() {
        return telNo.getText().toString().trim();
    }

    @Override
    public String getCode() {
        return verifyCode.getText().toString().trim();
    }

    @Override
    public void startTimer() {
        verifyGet.startTimer();
    }

    @Override
    public void startModifyPsdActivity(String phoneNo) {
        Intent intent=new Intent(this,ModifyPsdActivity.class);
        intent.putExtra("forget",phoneNo);
        startActivity(intent);
    }
}
